﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using NTTDATA.BEENChina.ResultCertification.Config;
using NTTDATA.BEENChina.ResultCertification.PropertyGridUtil;
using NTTDATA.BEENChina.ResultCertification.PropertyGridUtil.CustomObject;

namespace NTTDATA.BEENChina.ResultCertification.Checker.Address
{
    [Serializable]
    [VerfityAttribute(Id = "VerfityA0008", Name = "mansion栏为特定项目时抽出", CategoryType = EnumCategoryType.住所, Model = true)]
    public class VerfityA0008 : VerfityOneResult
    {
        private CustomCollection<SpecialStringArray> _datalist = new CustomCollection<SpecialStringArray>() { Description = "指定数据列表" };


        [Category("指定数据列表"), Description("输入指定数据项目")]
        [TypeConverter(typeof(CustomCollectionConverter<SpecialStringArray>))]
        [RefreshProperties(RefreshProperties.All)]
        public CustomCollection<SpecialStringArray> DataList
        {
            get { return _datalist; }
            //set { _rangelist = value; }
        }

        [Category("指定付笺值"), Description("输入指定付笺值，不指定时不填写")]
        public string SpecialCommon { get; set; }

        public override bool CheckResult(List<List<string>> result, string entryCommon)
        {
            bool bresult = false;
            if (entryCommon.Equals("30"))
            {
                return false;
            }

            if (result == null)
            {
                return false;
            }

            if (!String.IsNullOrEmpty(SpecialCommon))
            {

                if (!entryCommon.Equals(SpecialCommon))
                {
                    bresult = true;
                }
            }


            /*        //也可以按组查询 指定行列为特定值 
                    bresult = DataList.Select(t => t.Group).Distinct()
                                         .Any(g => DataList.Where(t => t.Group.Equals(g))
                                          .All(o =>
                                           
                                                      CheckSpecificCharacter(result, GetSpeicficResult, o.Check)
                                            
                                              ));*/

            bresult = DataList.Where(t => !Enum.GetName(typeof(EnumSpecialType), t.SpecialType).Contains("Un"))
                             .Select(t => t.Group).Distinct()
                             .Any(g => DataList.Where(t => t.Group.Equals(g))
                             .All(o => CheckSpecificCharacter(result, GetSpeicficResult, o.Check)));

            //包含
            if (bresult)
            {
                //不包含
                //也可以按组查询 指定行列为特定值 
                bresult = DataList.Where(t => Enum.GetName(typeof(EnumSpecialType), t.SpecialType).Contains("Un"))
                                  .Select(t => t.Group).Distinct()
                                  .Any(g => DataList.Where(t => t.Group.Equals(g))
                                  .Any(o => CheckSpecificCharacter(result, GetSpeicficResult, o.Check)));
            }

            if (bresult)
            {
                System.Console.WriteLine(Id);
                System.Console.WriteLine(base.Memo);
            }

            return bresult;
        }

        private string GetSpeicficResult(string colResult)
        {
            var splitResult = new Split.SplitEntryResult(ChildImageObject.CategorySetting.DataFormat, colResult);
            return splitResult.GetMansion();
            //return splitResult.GetNumberMansion();
        }

        //protected  bool CheckspecificResult(int row, int col, string result )
        //{

        //  bool bresult = false;

        //    if (String.IsNullOrEmpty(result))
        //    {
        //        return false;
        //    }

        //    bresult = DataList.All(t => t.Check(row, col, result));

        //    return bresult; 
        //}
    }
}
